fn variables() {
    let a: i32 = 1;
    let b: u32 = 1;
    let c = -2;
    let d = '😻';
    let t = (a, b, c, d, c);
    let (e, f, g, h, i) = t;
    println!("a = {}, b = {}, c = {}, d = {}", a, b, c, d);
    println!("e = {}, f = {}, g = {}, h = {}, i = {}", e, f, g, h, i);
    println!("t = {:?}", t);
    println!("e = {}, f = {}, g = {}, h = {}", t.0, t.1, t.2, t.3);

    let mut arr = [1,2,3,4,5];//[1; 5];
    println!("arr = {:?}, len={}, slice={:?}", arr, arr.len(), &arr[1..3]);
    // println!("arr = {:#?}", arr); // {:#?} means pretty print

    let idx = 2;
    arr[idx] = 3;
    let a = 3;
    println!("arr = {:?}", arr);
    println!("add(a+b) = {}, {}", add(a, b), add_return(a, b));

    let s = String::from("Hello world");
    borrow_string(s);
    // println!("String is now: {}", s); // value borrowed here after move

    let s = String::from("Hello again");
    let s = borrow_string_and_return(s);
    println!("String is now: {}", s);

    ref_string(&s);
    println!("String is now: {}", s);
    
    let mut sm = String::from("change me");
    change_str(&mut sm);
    println!("String is now: {}", sm);

    println!("First word: {}", first_word("big big girl in a big big world"));
}

fn add(a: u32, b: u32) -> u32 {
    a + b
}

fn add_return(a: u32, b: u32) -> u32 {
    return a + b;
}

fn borrow_string(s: String) {
    println!("string borrowed: {}", s);
}

fn borrow_string_and_return(s: String) -> String {
    println!("String borrowed and return: {}", s);
    s
}

fn ref_string(s: &String) {
    println!("String referenced: {}", s);
}

fn change_str(s: &mut String) {
    s.push_str(", and print it");
}

// fn dangle() -> &String {
//     let s = String::from("s: &str");
//     &s
// }

fn first_word(s: &str) -> &str {
    let it = s.split_whitespace();
    for v in it {
        return v;
    }
    return s
}